package MathTextModeller
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.text.*;
	import MyDisplayObjects.MyButton;
	
	/** Tells the user any information they need to know about this problem at the beginning, and displays a continue button */
	public class ProblemIntro extends MovieClip
	{
		
		// private objects not accessible
		private var continueButton:MyButton;
		private var tField:TextField;
		
		public function ProblemIntro(width:Number, height:Number, text:String = "")
		{
			this.graphics.drawRect(0, 0, width, height);
			
			// display text
			tField = new TextField();
			tField.selectable = false;
			tField.defaultTextFormat = new TextFormat("arial", width/50, 0x000000);
			tField.wordWrap = false;
			tField.text = text;
			tField.autoSize = "left";
			this.addChild(tField);
			tField.x = (this.width - tField.width)/2;
			tField.y = width/50;
			
			// place a continue button, place a listener so when completed this completes as well.
			continueButton = new MyButton(width/5, width/15, width/30, width/30, "I'm ready", 0x008800, 2);
			continueButton.addEventListener(MouseEvent.CLICK, handleContinuePressed);
			this.addChild(continueButton);
			continueButton.x = (this.width - continueButton.width)/2;
			continueButton.y = this.height - 2*continueButton.height;
		}
		
		/** When user clicks the continue button dispatch complete event */
		private function handleContinuePressed (event:MouseEvent):void
		{
			this.removeEventListener(MouseEvent.CLICK, handleContinuePressed);
			this.dispatchEvent (new Event(Event.COMPLETE));
		}
	}
}